import bot from "../model/bot/amesu";
import func from "../model/func";
import { transactionLog } from "../shared/interface";
import { MsgAction } from "../shared/master/MsgAction";
import { style_default } from "../style/default";

export default async function (data: MsgAction) {
    let d = data.data as transactionLog;
    let text = '';
    if (d.state) {
        text = await succress(d)
    } else {
        text = await faill(d)
    }

    bot.sendText(data.tolocation, text);
}

async function succress(data: transactionLog) {
    let s = new style_default();
    s.setTitle('消费凭证')
    s.addLine(`🕜️${func.getTimeStr(data.createTime)}`)
    s.addLine(`📄${data.reason}`);

    await s.addOne()
    if (data.gold.need > 0) {
        s.addLine(`💰️ -${func.BN(data.gold.need)}/${func.BN(data.gold.now)}`);
    }
    if (data.diamond.need > 0) {
        s.addLine(`世界之缘 -${func.BN(data.diamond.need)}/${func.BN(data.diamond.now)}`);
    }
    for (let i = 0; i < data.items.length; i++) {
        const element = data.items[i];
        s.addLine(`${element.name} -${func.BN(element.need)}/${func.BN(element.now)}`)
    }
    return s.end()
}
async function faill(data: transactionLog) {
    let s = new style_default();
    s.setTitle('交易失败')
    s.addLine(`🕜️${func.getTimeStr(data.createTime)}`)
    s.addLine(`📄${data.reason}`);
    if (data.gold.need > 0) {
        s.addLine(`💰️ 需${func.BN(data.gold.need)}当前有${func.BN(data.gold.now)}`);
    }
    if (data.diamond.need > 0) {
        s.addLine(`世界之缘 需${func.BN(data.diamond.need)}当前有${func.BN(data.diamond.now)}`);
    }
    for (let i = 0; i < data.items.length; i++) {
        const element = data.items[i];
        s.addLine(`${element.name} 需${func.BN(element.need)}当前有${func.BN(element.now)}`)
    }
    return s.end()
}